package com.tangsm.api.demo.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import java.util.List;

/**
 * Web 通用配置类
 * <p>处理api通用返回, @ControllerAdvice 接收String时 cannot be cast to java.lang.String问题</p>
 * <p>此方案WebMvcConfigurerAdapter类已过时, 不建议使用</p>
 * <p>此方案会导致日期类型的转换配置失效, spring.jackson.date-format: yyyy-MM-dd HH:mm:ss</p>
 * @author 湯神码
 * @date 2020/11/16
 * @date 2020/11/20 此类不生效，api返回String类型依旧报错，需要找原因
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    @Override
    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
        super.configureMessageConverters(converters);
        converters.add(0, new MappingJackson2HttpMessageConverter());
    }
}